<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>OPA | 登录</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/static/bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="/static/bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/css/AdminLTE.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="/static/plugins/iCheck/square/blue.css">
</head>
<body class="hold-transition login-page" style="background: url(/static/sky-bg.jpg) no-repeat; background-size: cover">
<div class="login-box">
  <div class="login-logo">
    <a href="/" style="color: #f9fafc"><b>OPA-运维管理平台</b></a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">账户登录</p>

    <form id="login-form">
      <div class="form-group has-feedback">
        <input type="text" id="username" name="username" class="form-control" placeholder="账户">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" id="password" name="password" class="form-control" placeholder="密码">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        <p style="color: red" class="text-center" for="password" id="error"><b></b></p>

      </div>

      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox" id="local_account" name="local_account" value="local_account"> 使用本地账号
            </label>
          </div>
        </div>
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
        </div>
      </div>
    </form>

    <a href="http://it.elemparticle.com/">忘记密码？</a><br>

  </div>
  <!-- /.login-box-body -->


</div>


  <div class="lockscreen-footer text-center" style="color: #f9fafc">
    Copyright &copy; 2023 <b>FuXiao</b><br>
    All rights reserved
  </div>




<!-- jQuery 3 -->
<script src="/static/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="/static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="/static/plugins/iCheck/icheck.min.js"></script>
<!-- bootbox -->
<script src="/static/js/bootbox.min.js"></script>

<!-- 自己写的一些常用工具 -->
<script src="/static/js/common_tools.js"></script>

<script>
    // 页面载入完毕后执行接口调用
    $(function () {
        // 设置本地登录checkbox的样式
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '100%', // optional
        });
        // 记录本地登录checkbox的勾选动作，是否勾选
        $('#local_account').on('ifChecked', function (event) {
            // alert(event.type + ' callback');
            localStorage.setItem("local_account", "checked")
        });
        $('#local_account').on('ifUnchecked', function (event) {
            // alert(event.type + ' callback');
            localStorage.setItem("local_account", "unchecked")
        });

        // 载入并处理本地存储的checkbox勾选状态
        let local_account = localStorage.getItem("local_account")
        if (local_account === 'checked') {
            $('#local_account').iCheck('check')
        }

        // 处理登录逻辑
        $('#login-form').on('submit', function (event) {
            event.preventDefault(); //阻止表单默认提交事件
            let data = {
                username: $('#username').val(),
                password: $('#password').val(),
                local_account: localStorage.getItem("local_account"),
                back_url: getQueryString('backpath')
            }
            // 验证账号密码是否正确
            $.ajax({
                url: '/api/v1/login',
                method: 'POST',
                data: JSON.stringify(data),
                contentType: "application/json",
                dataType: "json",
                success: function (result) {
                    console.log(result)
                    let url = getQueryString('backpath')
                    if (url == '') {
                        url = '/'
                    }
                    window.location.href = url;
                },
                error: function () {
                    $('#error').text("账号密码错误")
                }

            })
        })


    });
</script>


</body>
</html>

